package com.ruoyi.lab.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.lab.service.ILabMessageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lab.domain.LabSeatMessage;
import com.ruoyi.lab.service.ILabSeatMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 实验室座位表Controller
 * 
 * @author dn
 * @date 2023-12-31
 */
@RestController
@RequestMapping("/lab/seatMessage")
public class LabSeatMessageController extends BaseController
{
    @Autowired
    private ILabSeatMessageService labSeatMessageService;

    @Autowired
    private ILabMessageService labMessageService;

    /**
     * 查询实验室座位表列表
     */
    @PreAuthorize("@ss.hasPermi('lab:seatMessage:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabSeatMessage labSeatMessage)
    {
        startPage();
        List<LabSeatMessage> list = labSeatMessageService.selectLabSeatMessageList(labSeatMessage);
        return getDataTable(list);
    }

    /**
     * 导出实验室座位表列表
     */
    @PreAuthorize("@ss.hasPermi('lab:seatMessage:export')")
    @Log(title = "实验室座位表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabSeatMessage labSeatMessage)
    {
        List<LabSeatMessage> list = labSeatMessageService.selectLabSeatMessageList(labSeatMessage);
        ExcelUtil<LabSeatMessage> util = new ExcelUtil<LabSeatMessage>(LabSeatMessage.class);
        util.exportExcel(response, list, "实验室座位表数据");
    }

    /**
     * 导入座位信息
     * @return
     */
    @PreAuthorize("@ss.hasPermi('lab:seatMessage:export')")
    @PostMapping("/import")
    public AjaxResult importData(MultipartFile file) {
        Boolean result = labMessageService.importData(file);
        if (result) return AjaxResult.success("导入成功");
        else return AjaxResult.error("导入信息有误");
    }

    /**
     * 获取实验室座位表详细信息
     */
    @PreAuthorize("@ss.hasPermi('lab:seatMessage:query')")
    @GetMapping(value = "/{seatId}")
    public AjaxResult getInfo(@PathVariable("seatId") Long seatId)
    {
        return success(labSeatMessageService.selectLabSeatMessageBySeatId(seatId));
    }

    /**
     * 新增实验室座位表
     */
    @PreAuthorize("@ss.hasPermi('lab:seatMessage:add')")
    @Log(title = "实验室座位表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabSeatMessage labSeatMessage)
    {
        return toAjax(labSeatMessageService.insertLabSeatMessage(labSeatMessage));
    }

    /**
     * 修改实验室座位表
     */
    @PreAuthorize("@ss.hasPermi('lab:seatMessage:edit')")
    @Log(title = "实验室座位表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabSeatMessage labSeatMessage)
    {
        return toAjax(labSeatMessageService.updateLabSeatMessage(labSeatMessage));
    }

    /**
     * 删除实验室座位表
     */
    @PreAuthorize("@ss.hasPermi('lab:seatMessage:remove')")
    @Log(title = "实验室座位表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{seatIds}")
    public AjaxResult remove(@PathVariable Long[] seatIds)
    {
        return toAjax(labSeatMessageService.deleteLabSeatMessageBySeatIds(seatIds));
    }
}
